
/*
 * @Author: 于建霞
 * @Date: 2020-11-Mo 03:44:32
 * @Last Modified by:   于建霞
 * @Last Modified time: 2020-11-Mo 03:44:32
 * 
 * * @description:  送别或者撤销弹框
 */
import React, { useState, useCallback, useRef, useEffect } from 'react';
import { Modal, Button, message } from 'antd';
import ProTable from '@ant-design/pro-table';
import { useRequest } from '@umijs/hooks';
import { seeOffVip, revokeVip } from '../../service';

/**
 * @param {farewellOrCancel, //送别或者撤销类型（farewell/cancel）
 * farewellVisible, //显隐
 * setFarewellVisible //控制显示函数
 * selectRow //选中的项
 * } props 
 */

const AddEntourage = (props) => {
    // console.log('props :>> ', props);
    const { farewellOrCancel,farewellVisible, setFarewellVisible, selectRow, reloadTable } = props;
    
    const { run:seeOffOrRevokeVip, loading:getVipInfoLoading } = useRequest((flightInfo)=> {
        console.log('flightInfo', flightInfo)
       return farewellOrCancel === 'farewell' ?  seeOffVip(flightInfo) : revokeVip(flightInfo);
    },{
        manual: true,
        onSuccess: (data) => {
            console.log('返回的息11111111', data);
            message.success('操作成功')
            reloadTable()
            setFarewellVisible(false);
        }
    })

    const handleOk = () => {
        let alongIdsArr = []; //随行的id集合
        let vipIdsArr = []; //贵宾的id集合
        for (const item of selectRow) {
            if (item.isAcmp == 1) { //随行
                alongIdsArr.push(item.id);
            }else{
                vipIdsArr.push(item.id);
            }
        }
        seeOffOrRevokeVip({
            ids:vipIdsArr.join(','), //贵宾的ids
            acmpIds:alongIdsArr.join(',') //随行的ids
        });
    }
    const handleCancel = () => {
        setFarewellVisible(false);
    }

    let columns = [
        {
            title: '',
            dataIndex: 'index',
            valueType: 'index',
            width: 60,
        },
        {
            dataIndex: 'flightNo',
            title: '航班号',
        }, {
            dataIndex: 'paxName',
            title: '旅客姓名',
        }, {
            dataIndex: 'paxTypeDesc',
            title: '旅客类型',
        },
    ]
    return (
        <Modal
            title={farewellOrCancel === 'farewell' ? '贵宾送别' : '贵宾撤销'}
            visible={farewellVisible}
            maskClosable={false}
            width="660px"
            onCancel={handleCancel}
            footer={
                <>
                    <Button onClick={handleCancel}>取消</Button>
                    <Button loading={getVipInfoLoading} onClick={handleOk}>{farewellOrCancel === 'farewell' ? '送别' : '确定'}</Button>
                </>
            }
        >
            <p style={{fontSize:"16px",color:"rgb(0 0 0 / 85%)",fontWeight:"500"}}>{farewellOrCancel === 'farewell' ? '是否送别以下旅客？' : '是否为以下旅客执行操作？'}</p>
            <ProTable
                columns={columns}
                dataSource={selectRow}
                rowKey="id"
                pagination={false}
                toolBarRender={false}
                search={false}
            />
        </Modal>
    )
}

export default AddEntourage